﻿#include "AmapViewImpl.h"

#include "EAGLView.h"

#import <MAMapKit/MAMapKit.h>
#import <AMapLocationKit/AMapLocationManager.h>

#import <AMapSearchKit/AMapSearchKit.h>
#import <AMapLocationKit/AMapLocationManager.h>

#import "LineDashPolyline.h"
#import "MANaviRoute.h"
#import "MANaviPolyline.h"

#define AmapViewWrapper ((UIAmapViewWrapper*)m_pAmapWrapper)

@interface UIAmapViewWrapper : NSObject<MAMapViewDelegate, AMapLocationManagerDelegate, AMapSearchDelegate>

@property(nonatomic, retain) MAMapView* mAmapView;

@property(nonatomic, retain) AMapLocationManager* mLocManager;

@property(nonatomic, retain) AMapSearchAPI* mSearch;

@property(nonatomic, retain) UIButton* mZoominBt;//放大按钮

@property(nonatomic, retain) UIButton* mZoomoutBt;//缩小按钮

@property(nonatomic, retain) UIButton* mLocationBt;//定位按钮

@property(nonatomic, assign) float mfZoomLevel;//缩放比例

@property(nonatomic, assign) double mdLat;//纬度

@property(nonatomic, assign) double mdLng;//经度

@property(nonatomic, assign) BOOL mbAmapLoaded;//地图是否加载成功

@property(nonatomic, assign) BOOL mbLoc;//是否定位

@property(nonatomic, assign) BOOL mbRouteSearch;//是否搜索

@property(nonatomic, retain) MAPointAnnotation* mLocationAn;

@property(nonatomic, retain) MAPointAnnotation* mStartAn;

@property(nonatomic, retain) MAPointAnnotation* mEndAn;

/* 起始点经纬度. */
@property (nonatomic, retain) AMapGeoPoint* mStartPoint;
/* 终点经纬度. */
@property (nonatomic, retain) AMapGeoPoint* mEndPoint;

@property(nonatomic, assign) NSString* mstrCity;//公交路线起始点城市
@property(nonatomic, assign) NSString* mstrCityD;///公交路线目标点城市

@property(nonatomic, assign) int miRouteType;//路线类型 1、驾车 2、公交 3、步行

@property (nonatomic, retain) AMapRoute* mRoute;

/* 用于显示当前路线方案. */
@property (nonatomic, retain) MANaviRoute * naviRoute;

@property(nonatomic, strong) NSMutableDictionary* _MarkAnViews;

@end

@implementation UIAmapViewWrapper


+ (instancetype)amapWrapper
{
    return [[[self alloc] init] autorelease];
}

- (instancetype)init
{
    self = [super init];
    if (self)
    {
        self.mAmapView = nil;
        
        self.mLocManager = nil;
        
        self.mZoominBt = nil;
        self.mZoomoutBt = nil;
        self.mLocationBt = nil;
        
        self.mLocationAn = nil;
        
        self.mfZoomLevel = 10.0;
        
        self.mbLoc = NO;
        
        self.mdLat = 39.9;
        self.mdLng = 116.3;
        
        self._MarkAnViews = [[NSMutableDictionary alloc] init];
        
        self.mbAmapLoaded = NO;
        
        self.mStartAn = nil;
        self.mEndAn = nil;
        
        self.mSearch = nil;
        self.mRoute = nil;
        self.mStartPoint = nil;
        self.mEndPoint = nil;
        self.mstrCity = nil;
        self.mstrCityD = nil;
        
        self.naviRoute = nil;
        
        self.mdLat = 39.9;
        self.mdLng = 116.3;
        
        self.miRouteType = 0;
        
        
        [self setupAMapView];
    }
    return self;
}

- (void)dealloc
{
    [self.mLocManager stopUpdatingLocation];
    [self.mLocManager setDelegate:nil];
    [self.mLocManager release];
    
    [self.mAmapView removeAnnotation : self.mLocationAn];
    [self.mLocationAn release];
    
    [self.mAmapView removeAnnotation : self.mStartAn];
    [self.mStartAn release];
    
    [self.mAmapView removeAnnotation : self.mEndAn];
    [self.mEndAn release];
    
    [self.naviRoute removeFromMapView];
    [self.naviRoute release];
    
    [self.mSearch release];
    
    [self.mRoute release];
    
    [self.mZoominBt removeFromSuperview];
    [self.mZoominBt release];
    
    [self.mZoomoutBt removeFromSuperview];
    [self.mZoomoutBt release];
    
    [self.mLocationBt removeFromSuperview];
    [self.mLocationBt release];
    
    [self clearMarkers];
    [self._MarkAnViews release];
    
    self.mstrCity = nil;
    self.mstrCityD = nil;
    
    [self.mAmapView release];
    
    [super dealloc];
}

- (void)setFrameWith_X:(float)x Y:(float)y Width:(float)width Height:(float)height
{
    if (!self.mAmapView)
    {
        [self setupAMapView];
    }
    
    CGFloat scale = [[UIScreen mainScreen] scale];
    float eightW = s_dip_to_px(80) / scale;
    float twoW = s_dip_to_px(20) / scale;
    
    CGRect newFrame = CGRectMake(x, y, width, height);
    [self.mAmapView setFrame:newFrame];
    
    CGRect locationFrame = CGRectMake(width - twoW - eightW, twoW, eightW, eightW);
    [self.mLocationBt setFrame:locationFrame];
    
    CGRect zoominFrame = CGRectMake(width - twoW - eightW, height - eightW - eightW - twoW, eightW, eightW);
    [self.mZoominBt setFrame:zoominFrame];
        
    CGRect zoomoutFrame = CGRectMake(width - twoW - eightW, height - eightW - twoW, eightW, eightW);
    [self.mZoomoutBt setFrame:zoomoutFrame];
    
    if (!self.mbAmapLoaded)
    {
        self.mbAmapLoaded = YES;
        
        [self.mAmapView addAnnotation:self.mLocationAn];
        
        if ([self._MarkAnViews count] > 0)
        {
            for(id key in self._MarkAnViews.allKeys)
            {
                MAPinAnnotationView* newpinView = [self._MarkAnViews objectForKey:key];
                if (newpinView != nil)
                {
                    [self.mAmapView addAnnotation:newpinView.annotation];
                }
            }
        }
        
        [self.mAmapView setZoomLevel:self.mfZoomLevel animated:NO];
        
        [self.mAmapView setCenterCoordinate:CLLocationCoordinate2DMake(self.mdLat, self.mdLng) animated:NO];
        
        if ([self._MarkAnViews count] > 0)
        {
            MAPinAnnotationView* newpinView = [self._MarkAnViews objectForKey:self._MarkAnViews.allKeys[0]];
            
            [self.mAmapView selectAnnotation:newpinView.annotation animated:YES];
        }
        
        if (self.mbRouteSearch)
        {
            [self searchRoute];
        }
        
        if (self.mbLoc)
        {
            [self startLocation];
        }
    }
}

- (void)setupAMapView
{
    if (!self.mAmapView)
    {
        self.mAmapView = [[MAMapView alloc] init];
        [self.mAmapView setDelegate:self];
    }
    if (!self.mAmapView.superview)
    {
        EAGLView * eaglview = [EAGLView sharedEGLView];
        [eaglview addSubview:self.mAmapView];
        [eaglview bringSubviewToFront:self.mAmapView];
    }
    
    if (!self.mLocManager)
    {
        self.mLocManager = [[AMapLocationManager alloc]init];
        [self.mLocManager setDelegate:self];
        //设置不允许系统暂停定位
        [self.mLocManager setPausesLocationUpdatesAutomatically:NO];
        //设置期望定位精度
        [self.mLocManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
    }
    
    if (!self.mZoominBt)
    {
        self.mZoominBt = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.mZoominBt addTarget:self action:@selector(zoominbtnPressed:) forControlEvents:UIControlEventTouchUpInside];
        [self.mZoominBt setImage:[UIImage imageNamed:@"zoomin_selected2d"] forState:UIControlStateNormal];
    }
    if (!self.mZoominBt.superview)
    {
        [self.mAmapView addSubview:self.mZoominBt];
    }
    
    if (!self.mZoomoutBt)
    {
        self.mZoomoutBt = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.mZoomoutBt addTarget:self action:@selector(zoomoutbtnPressed:) forControlEvents:UIControlEventTouchUpInside];
        [self.mZoomoutBt setImage:[UIImage imageNamed:@"zoomout_selected2d"] forState:UIControlStateNormal];
    }
    if (!self.mZoomoutBt.superview)
    {
        [self.mAmapView addSubview:self.mZoomoutBt];
    }
    
    if (!self.mLocationBt)
    {
        self.mLocationBt = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.mLocationBt addTarget:self action:@selector(locationbtnPressed:) forControlEvents:UIControlEventTouchUpInside];
        [self.mLocationBt setImage:[UIImage imageNamed:@"location_selected2d"] forState:UIControlStateNormal];
    }
    if (!self.mLocationBt.superview)
    {
        [self.mAmapView addSubview:self.mLocationBt];
    }
    
    if (!self.mLocationAn)
    {
        self.mLocationAn = [[MAPointAnnotation alloc] init];
        [self.mLocationAn setTitle:@"我的位置"];
        [self.mLocationAn setSubtitle:@""];
    }
    
    if (!self.mStartAn)
    {
        self.mStartAn = [[MAPointAnnotation alloc] init];
        [self.mStartAn setTitle:@"起点"];
    }
    
    if (!self.mEndAn)
    {
        self.mEndAn = [[MAPointAnnotation alloc] init];
        [self.mEndAn setTitle:@"终点"];
    }
    
    if (!self.mSearch)
    {
        self.mSearch = [[AMapSearchAPI alloc] init];
        self.mSearch.delegate = self;
    }
}

- (void)zoominbtnPressed:(id)sender
{
    if (self.mAmapView != nil)
    {
        double level = [self.mAmapView zoomLevel];
        level += 0.5;
        [self.mAmapView setZoomLevel:level animated:YES];
    }
}

- (void)zoomoutbtnPressed:(id)sender
{
    if (self.mAmapView != nil)
    {
        double level = [self.mAmapView zoomLevel];
        level -= 0.5;
        [self.mAmapView setZoomLevel:level animated:YES];
    }
}

- (void)setMapCenterLat:(double)lat Lng:(double)lng
{
    self.mbLoc = NO;
    
    self.mdLat = lat;
    self.mdLng = lng;
    
    if (self.mbAmapLoaded)
    {
        [self.mAmapView setZoomLevel:[self.mAmapView zoomLevel] animated:NO];
        [self.mAmapView setCenterCoordinate:CLLocationCoordinate2DMake(lat, lng) animated:NO];
    }
}

- (void)locationbtnPressed:(id)sender
{
    [self startLocation];
}

- (void)startLocation
{
    self.mbLoc = YES;
    if (self.mbAmapLoaded && self.mLocManager)
    {
        [self.mLocManager requestLocationWithReGeocode:YES completionBlock:^(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error)
         {
             if (error != nil && error.code == AMapLocationErrorLocateFailed)
             {
                 //定位错误：此时location和regeocode没有返回值，不进行annotation的添加
                 AmapViewImpl::onAmapLocationEnd(self, -2, 0.0, 0.0, "", "", "", "", "", "", "", "");
                 return;
             }
             else if (error != nil
                      && (error.code == AMapLocationErrorReGeocodeFailed
                          || error.code == AMapLocationErrorTimeOut
                          || error.code == AMapLocationErrorCannotFindHost
                          || error.code == AMapLocationErrorBadURL
                          || error.code == AMapLocationErrorNotConnectedToInternet
                          || error.code == AMapLocationErrorCannotConnectToHost))
             {
                 //逆地理错误：在带逆地理的单次定位中，逆地理过程可能发生错误，此时location有返回值，regeocode无返回值，进行annotation的添加
                 AmapViewImpl::onAmapLocationEnd(self, -1, location.coordinate.latitude, location.coordinate.longitude, "", "", "", "", "", "", "", "");
                 return;
             }
             else
             {
                 //没有错误：location有返回值，regeocode是否有返回值取决于是否进行逆地理操作，进行annotation的添加
                 AmapViewImpl::onAmapLocationEnd(self, 0, location.coordinate.latitude, location.coordinate.longitude, [regeocode.formattedAddress UTF8String], [regeocode.province UTF8String], [regeocode.city UTF8String], [regeocode.district UTF8String], [regeocode.street UTF8String], [regeocode.number UTF8String], [regeocode.POIName UTF8String], [regeocode.adcode UTF8String]);
             }
             
             //修改Location显示内容
             if (location && regeocode)
             {
                 self.mdLat = location.coordinate.latitude;
                 self.mdLng = location.coordinate.longitude;
                 if (self.mbAmapLoaded)
                 {
                     [self.mAmapView setZoomLevel:16.0 animated:NO];
                     [self.mAmapView setCenterCoordinate:location.coordinate animated:NO];
                     
                     [self.mLocationAn setTitle:regeocode.formattedAddress];
                     [self.mLocationAn setCoordinate:location.coordinate];
                     
                     [self.mAmapView selectAnnotation:self.mLocationAn animated:YES];
                 }
             }
             
         }];
    }
}

- (void)stopLocation
{
    if (self.mLocManager)
    {
        [self.mLocManager stopUpdatingLocation];
    }
}

- (void)setMapZoomLevel:(double)level
{
    self.mfZoomLevel = level;
    
    if (self.mbAmapLoaded)
    {
        [self.mAmapView setZoomLevel:level];
    }
}

- (void)addMarkerTag:(NSString*)tag Image: (NSString*) imgurl Draggable:(BOOL) draggable Title:(NSString*) title Content:(NSString*)content Lat:(double)lat Lng:(double) lng
{
    MAPointAnnotation* pointAn = [[MAPointAnnotation alloc]init];
    [pointAn setCoordinate:CLLocationCoordinate2DMake(lat, lng)];
    [pointAn setTitle:title];
    [pointAn setSubtitle:content];
    
    MAPinAnnotationView* pinAnView = [[MAPinAnnotationView alloc] init];
    [pinAnView setAnnotation:pointAn];
    [pinAnView setDraggable:draggable];
    [pinAnView setImage:[UIImage imageNamed:imgurl]];
    
    [self._MarkAnViews setObject:pinAnView forKey:tag];
    
    if (self.mbAmapLoaded)
    {
        [self.mAmapView addAnnotation:pointAn];
        [self.mAmapView selectAnnotation:pointAn animated:YES];
    }
}

- (void)deleteMarkerTag:(NSString*)tag
{
    MAPinAnnotationView* pinAnView = [self._MarkAnViews objectForKey:tag];
    if (pinAnView != nil)
    {
        [self.mAmapView removeAnnotation:pinAnView.annotation];
        [self._MarkAnViews removeObjectForKey:tag];
    }
}

- (void)clearMarkers
{
    for(id key in self._MarkAnViews.allKeys)
    {
        MAPinAnnotationView* newpinView = [self._MarkAnViews objectForKey:key];
        if (newpinView != nil)
        {
            [self.mAmapView removeAnnotation:newpinView.annotation];
        }
    }
    
    [self._MarkAnViews removeAllObjects];
}

- (void)setVisible:(bool)visible
{
    self.mAmapView.hidden = !visible;
}

- (void)setAmapRouteViewTypeSLat:(double)slat SLng:(double)slng ELat:(double)elat ELng:(double)elng Type:(int)type
{
    self.mStartPoint = [AMapGeoPoint locationWithLatitude:slat longitude:slng];
    self.mEndPoint = [AMapGeoPoint locationWithLatitude:elat longitude:elng];
    self.miRouteType = type;
}

- (void)searchRoute
{
    self.mbRouteSearch = true;
    
    if (self.mbAmapLoaded)
    {
        switch(self.miRouteType)
        {
            case 1:
            default:
            {
                AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
                
                navi.requireExtension = YES;
                /* 出发点. */
                navi.origin = self.mStartPoint;
                /* 目的地. */
                navi.destination = self.mEndPoint;
                
                [self.mSearch AMapDrivingRouteSearch:navi];
                
                break;
            }
            case 2:
            {
                if (self.mstrCity != nil && ![self.mstrCity isEqual: @""])
                {
                    AMapTransitRouteSearchRequest *navi = [[AMapTransitRouteSearchRequest alloc] init];
                    
                    navi.requireExtension = YES;
                    navi.city             = self.mstrCity;
                    if (self.mstrCityD != nil && ![self.mstrCityD isEqual: @""])
                    {
                        navi.destinationCity = self.mstrCityD;
                    }
                    /* 出发点. */
                    navi.origin = self.mStartPoint;
                    /* 目的地. */
                    navi.destination = self.mEndPoint;
                    
                    [self.mSearch AMapTransitRouteSearch:navi];
                }
                
                break;
            }
            case 3:
            {
                AMapWalkingRouteSearchRequest *navi = [[AMapWalkingRouteSearchRequest alloc] init];
                
                /* 出发点. */
                navi.origin = self.mStartPoint;
                /* 目的地. */
                navi.destination = self.mEndPoint;
                
                [self.mSearch AMapWalkingRouteSearch:navi];
                
                break;
            }
        }
    }
}

- (void) showBusRouteView:(int) busTag
{
    [self presentBusRouteView:busTag];
}

- (void) setBusRouteCity:(NSString*)city CityD:(NSString*)cityd
{
    self.mstrCity = city;
    self.mstrCityD = cityd;
}

- (void) getBusRouteStep:(int) busTag
{
    std::vector<BusRouteStep> v_datas;
    
    AMapTransit * tran = [self.mRoute.transits objectAtIndex:busTag];
    if (tran != nil)
    {
        v_datas.reserve(tran.segments.count);
        
        NSArray<AMapSegment *> *segments = [tran segments];
        for (AMapSegment* seg in segments)
        {
            if (seg.walking != nil && seg.walking.distance > 0)
            {
                BusRouteStep step;
                step.type = 1;
                
                step.name = string("步行") + [[NSString stringWithFormat:@"%d米", (int)[seg.walking distance]] UTF8String];
                step.distance = seg.walking.distance;
                step.duration = seg.walking.duration;
                step.stations = "";
                
                v_datas.push_back(step);
            }
            
            if (seg.buslines != nil && seg.buslines.count > 0)
            {
                BusRouteStep step;
                step.type = 2;
                
                step.name = [[seg.buslines objectAtIndex:0].name UTF8String];
                step.distance = [[seg.buslines objectAtIndex:0] distance];
                step.duration = [[seg.buslines objectAtIndex:0] duration];
                
                string stations = "";
                
                stations += [[[[seg.buslines objectAtIndex:0] departureStop] name] UTF8String];
                stations += "/";
                
                NSArray<AMapBusStop*> * busstops = [[seg.buslines objectAtIndex:0] viaBusStops];
                for (AMapBusStop * busstop in busstops)
                {
                    stations += [[busstop name] UTF8String];
                    stations += "/";
                }
                
                stations += [[[[seg.buslines objectAtIndex:0] arrivalStop] name] UTF8String];
                
                step.stations = stations;
                
                v_datas.push_back(step);
            }
            
            if (seg.railway != nil && seg.railway.name != nil)
            {
                BusRouteStep step;
                step.type = 3;
                
                step.name = [seg.railway.name UTF8String];
                step.distance = seg.railway.distance;
                step.duration = seg.railway.time;
                
                string stations = "";
                
                stations += [seg.railway.departureStation.name UTF8String];
                stations += "/";
                
                NSArray<AMapRailwayStation *>* stops = seg.railway.viaStops;
                for (AMapRailwayStation * stop in stops)
                {
                    stations += [[stop name] UTF8String];
                    stations += "/";
                }
                
                stations += [seg.railway.arrivalStation.name UTF8String];
                
                step.stations = stations;
                
                v_datas.push_back(step);
            }
            
            if (seg.taxi != nil)
            {
                BusRouteStep step;
                step.type = 4;
                
                step.name = "打车";
                step.distance = seg.taxi.distance;
                step.duration = seg.taxi.duration;
                
                step.stations = "";
                
                v_datas.push_back(step);
            }
        }
        
        AmapViewImpl::onBusRouteSteps(self, 0, busTag, v_datas);
    }
    else
    {
        AmapViewImpl::onBusRouteSteps(self, -1, busTag, v_datas);
    }
}

- (NSString*) getBusPathTitle:(AMapTransit*)trans
{
    NSString* bustitle = @"";
    
    NSArray<AMapSegment *> *segments = [trans segments];
    
    for (AMapSegment * segment in segments)
    {
        AMapRailway *railway = segment.railway;
        if (railway.uid)
        {
            bustitle = [bustitle stringByAppendingString:railway.name];
            bustitle = [bustitle stringByAppendingString:@" > "];
        }
        else if (segment.buslines.count > 0)
        {
            AMapBusLine * busline = [segment.buslines objectAtIndex:0];
            bustitle = [bustitle stringByAppendingString: [busline name]];
            bustitle = [bustitle stringByAppendingString:@" > "];
        }
    }
    
    if ([bustitle length] > 3)
    {
        bustitle = [bustitle substringToIndex:[bustitle length] - 3];
    }
    
    return bustitle;
}

/* 展示驾车、步行路线方案. */
- (void)presentRouteView
{
    [self.naviRoute removeFromMapView];
    [self.naviRoute release];
    self.naviRoute = nil;
    
    [self clearMarkers];
    
    MANaviAnnotationType type = MANaviAnnotationTypeDrive;
    if (self.miRouteType == 2)
    {
        type = MANaviAnnotationTypeBus;
    }
    else if (self.miRouteType == 3)
    {
        type = MANaviAnnotationTypeWalking;
    }
    
    [self.mAmapView removeAnnotation:self.mStartAn];
    [self.mAmapView removeAnnotation:self.mEndAn];
    
    [self.mAmapView addAnnotation:self.mStartAn];
    [self.mAmapView addAnnotation:self.mEndAn];
    
    [self.mStartAn setCoordinate:CLLocationCoordinate2DMake([self.mStartPoint latitude], [self.mStartPoint longitude])];
    
    [self.mEndAn setCoordinate:CLLocationCoordinate2DMake([self.mEndPoint latitude], [self.mEndPoint longitude])];
    
    self.naviRoute = [MANaviRoute naviRouteForPath:self.mRoute.paths[0] withNaviType:type showTraffic:YES startPoint:self.mStartPoint endPoint:self.mEndPoint];
    [self.naviRoute addToMapView:self.mAmapView];
    
    /* 缩放地图使其适应polylines的展示. */
    [self.mAmapView showOverlays:self.naviRoute.routePolylines edgePadding:UIEdgeInsetsMake(20, 20, 20, 20) animated:YES];
}

/* 展示公交路线方案. */
- (void)presentBusRouteView:(int)bustag
{
    [self.naviRoute removeFromMapView];
    [self.naviRoute release];
    self.naviRoute = nil;
    
    [self clearMarkers];
    
    MANaviAnnotationType type = MANaviAnnotationTypeDrive;
    if (self.miRouteType == 2)
    {
        type = MANaviAnnotationTypeBus;
    }
    else if (self.miRouteType == 3)
    {
        type = MANaviAnnotationTypeWalking;
    }
    
    [self.mAmapView removeAnnotation:self.mStartAn];
    [self.mAmapView removeAnnotation:self.mEndAn];
    
    [self.mAmapView addAnnotation:self.mStartAn];
    [self.mAmapView addAnnotation:self.mEndAn];
    
    [self.mStartAn setCoordinate:CLLocationCoordinate2DMake([self.mStartPoint latitude], [self.mStartPoint longitude])];
    
    [self.mEndAn setCoordinate:CLLocationCoordinate2DMake([self.mEndPoint latitude], [self.mEndPoint longitude])];
    
    self.naviRoute = [MANaviRoute naviRouteForTransit:self.mRoute.transits[bustag] startPoint:self.mStartPoint endPoint:self.mEndPoint];
    [self.naviRoute addToMapView:self.mAmapView];
    
    /* 缩放地图使其适应polylines的展示. */
    [self.mAmapView showOverlays:self.naviRoute.routePolylines edgePadding:UIEdgeInsetsMake(20, 20, 20, 20) animated:YES];
}

#pragma mark - AMapLocationManagerDelegate
/**
 *  当定位发生错误时，会调用代理的此方法。
 *
 *  @param manager 定位 AMapLocationManager 类。
 *  @param error 返回的错误，参考 CLError 。
 */
- (void)amapLocationManager:(AMapLocationManager *)manager didFailWithError:(NSError *)error
{
    [self stopLocation];
    
    AmapViewImpl::onAmapLocationEnd(self, -2, 0.0, 0.0, "", "", "", "", "", "", "", "");
}

#pragma mark - MAMapViewDelegate

/**
 * @brief 单击地图底图调用此接口
 * @param mapView    地图View
 * @param coordinate 点击位置经纬度
 */
- (void)mapView:(MAMapView *)mapView didSingleTappedAtCoordinate:(CLLocationCoordinate2D)coordinate
{
    AmapViewImpl::onAmapClicked(self, coordinate.latitude, coordinate.longitude);
}

- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id<MAAnnotation>)annotation
{
    if ([annotation isKindOfClass:[MAPointAnnotation class]])
    {
        static NSString *pinIndetifier = @"pinIndetifier";
        MAPinAnnotationView *annotationView = (MAPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:pinIndetifier];
        if (annotationView == nil)
        {
            annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pinIndetifier];
        }
        
        annotationView.canShowCallout = YES;
        annotationView.animatesDrop = NO;
        
        if (annotation == self.mLocationAn)
        {
            annotationView.draggable = NO;
            annotationView.pinColor = MAPinAnnotationColorGreen;
        }
        else if (annotation == self.mStartAn)
        {
            annotationView.image = [UIImage imageNamed:@"startPoint"];
            annotationView.draggable = NO;
        }
        else if (annotation == self.mEndAn)
        {
            annotationView.image = [UIImage imageNamed:@"endPoint"];
            annotationView.draggable = NO;
        }
        else if ([annotation isKindOfClass:[MANaviAnnotation class]])
        {
            switch (((MANaviAnnotation*)annotation).type)
            {
                case MANaviAnnotationTypeRailway:
                {
                    annotationView.image = nil;
                    annotationView.image = [UIImage imageNamed:@"railway_station"];
                }
                    break;
                    
                case MANaviAnnotationTypeBus:
                {
                    annotationView.image = nil;
                    annotationView.image = [UIImage imageNamed:@"bus"];
                }
                    break;
                    
                case MANaviAnnotationTypeDrive:
                {
                    annotationView.image = nil;
                    annotationView.image = [UIImage imageNamed:@"car"];
                }
                    break;
                    
                case MANaviAnnotationTypeWalking:
                {
                    annotationView.image = nil;
                    annotationView.image = [UIImage imageNamed:@"man"];
                }
                    break;
                    
                default:
                    break;
            }
        }
        else
        {
            for(id key in self._MarkAnViews.allKeys)
            {
                MAPinAnnotationView* newpinView = [self._MarkAnViews objectForKey:key];
                if (newpinView != nil && (id<MAAnnotation>)[newpinView annotation] == annotation)
                {
                    if ([newpinView image] != nil)
                    {
                        [annotationView setImage:[newpinView image]];
                    }
                    else
                    {
                        annotationView.pinColor = MAPinAnnotationColorRed;
                    }
                    annotationView.draggable = newpinView.draggable;
                    
                    break;
                }
            }
        }
        
        return annotationView;
    }
    
    return nil;
}

- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id<MAOverlay>)overlay
{
    if ([overlay isKindOfClass:[LineDashPolyline class]])
    {
        MAPolylineRenderer *polylineRenderer = [[MAPolylineRenderer alloc] initWithPolyline:((LineDashPolyline *)overlay).polyline];
        polylineRenderer.lineWidth   = 8;
        polylineRenderer.lineDashPattern = @[@10, @15];
        polylineRenderer.strokeColor = [UIColor redColor];
        
        return polylineRenderer;
    }
    if ([overlay isKindOfClass:[MANaviPolyline class]])
    {
        MANaviPolyline *naviPolyline = (MANaviPolyline *)overlay;
        MAPolylineRenderer *polylineRenderer = [[MAPolylineRenderer alloc] initWithPolyline:naviPolyline.polyline];
        
        polylineRenderer.lineWidth = 8;
        
        if (naviPolyline.type == MANaviAnnotationTypeWalking)
        {
            polylineRenderer.strokeColor = self.naviRoute.walkingColor;
        }
        else if (naviPolyline.type == MANaviAnnotationTypeRailway)
        {
            polylineRenderer.strokeColor = self.naviRoute.railwayColor;
        }
        else
        {
            polylineRenderer.strokeColor = self.naviRoute.routeColor;
        }
        
        return polylineRenderer;
    }
    if ([overlay isKindOfClass:[MAMultiPolyline class]])
    {
        MAMultiColoredPolylineRenderer * polylineRenderer = [[MAMultiColoredPolylineRenderer alloc] initWithMultiPolyline:overlay];
        
        polylineRenderer.lineWidth = 8;
        polylineRenderer.strokeColors = [self.naviRoute.multiPolylineColors copy];
        polylineRenderer.gradient = YES;
        
        return polylineRenderer;
    }
    
    return nil;
}

/**
 * @brief 当选中一个annotation views时调用此接口
 * @param mapView 地图View
 * @param view 选中的annotationView
 */
- (void)mapView:(MAMapView *)mapView didSelectAnnotationView:(MAAnnotationView *)view
{
    for(id key in self._MarkAnViews.allKeys)
    {
        MAPinAnnotationView* newpinView = [self._MarkAnViews objectForKey:key];
        if (newpinView != nil && (id<MAAnnotation>)[newpinView annotation] == view.annotation)
        {
            AmapViewImpl::onAmapMarkerClick(self, [key UTF8String]);
            break;
        }
    }
}

/**
 * @brief 拖动annotation view时view的状态变化，ios3.2以后支持
 * @param mapView 地图View
 * @param view annotation view
 * @param newState 新状态
 * @param oldState 旧状态
 */
- (void)mapView:(MAMapView *)mapView annotationView:(MAAnnotationView *)view didChangeDragState:(MAAnnotationViewDragState)newState fromOldState:(MAAnnotationViewDragState)oldState
{
    NSString* newKey = nil;
    for(id key in self._MarkAnViews.allKeys)
    {
        MAPinAnnotationView* newpinView = [self._MarkAnViews objectForKey:key];
        if (newpinView != nil && (id<MAAnnotation>)[newpinView annotation] == view.annotation)
        {
            newKey = key;
            break;
        }
    }
    if (newKey != nil)
    {
        if (newState == MAAnnotationViewDragStateStarting)
        {
            AmapViewImpl::onAmapMarkerDragStart(self, [newKey UTF8String], [[view annotation] coordinate].latitude, [[view annotation] coordinate].longitude);
        }
        else if (newState == MAAnnotationViewDragStateDragging)
        {
            AmapViewImpl::onAmapMarkerDrag(self, [newKey UTF8String], [[view annotation] coordinate].latitude, [[view annotation] coordinate].longitude);
        }
        else if (oldState == MAAnnotationViewDragStateEnding && newState == MAAnnotationViewDragStateNone)
        {
            AmapViewImpl::onAmapMarkerDragEnd(self, [newKey UTF8String], [[view annotation] coordinate].latitude, [[view annotation] coordinate].longitude);
        }
    }
}

/**
 * @brief 标注view的calloutview整体点击时调用此接口
 * @param mapView 地图的view
 * @param view calloutView所属的annotationView
 */
- (void)mapView:(MAMapView *)mapView didAnnotationViewCalloutTapped:(MAAnnotationView *)view
{
    for(id key in self._MarkAnViews.allKeys)
    {
        MAPinAnnotationView* newpinView = [self._MarkAnViews objectForKey:key];
        if (newpinView != nil && (id<MAAnnotation>)[newpinView annotation] == view.annotation)
        {
            AmapViewImpl::onAmapMarkerInfoWindowClick(self, [key UTF8String]);
            break;
        }
    }
}

#pragma mark - AMapSearchDelegate

- (void)AMapSearchRequest:(id)request didFailWithError:(NSError *)error
{
    if ([request isKindOfClass:AMapDrivingRouteSearchRequest.class])
    {
        DriveRouteData data;
        
        AmapViewImpl::onDriveRouteSearched(self, -1, data);
    }
    else if ([request isKindOfClass:AMapTransitRouteSearchRequest.class])
    {
        std::vector<BusRouteData> datas;
        
        AmapViewImpl::onBusRouteSearched(self, -1, datas);
    }
    else if ([request isKindOfClass:AMapWalkingRouteSearchRequest.class])
    {
        WalkRouteData data;
        
        AmapViewImpl::onWalkRouteSearched(self, -1, data);
    }
}

- (NSString*)getFriendlyTime:(int)second
{
    if (second > 3600)
    {
        int hour = second / 3600;
        int minute = (second % 3600) / 60;
        
        return [NSString stringWithFormat:@"%d小时%d分钟", hour, minute];
    }
    
    if (second >= 60)
    {
        int minute = second / 60;
        return [NSString stringWithFormat:@"%d分钟", minute];
    }
    
    return [NSString stringWithFormat:@"%d秒", second];
}

- (NSString*)getFriendlyLength:(int)length
{
    if (length > 10000)
    {
        int dis = length / 1000;
        return [NSString stringWithFormat:@"%d千米", dis];
    }
    
    if (length > 1000)
    {
        float dis = (float)length / 1000;
        return [NSString stringWithFormat:@"%.2f千米", dis];
    }
    
    if (length > 100)
    {
        int dis = length / 50 * 50;
        return [NSString stringWithFormat:@"%d米", dis];
    }
    
    return [NSString stringWithFormat:@"%d米", length];
}

/* 路径规划搜索回调. */
- (void)onRouteSearchDone:(AMapRouteSearchBaseRequest *)request response:(AMapRouteSearchResponse *)response
{
    if ([request isKindOfClass:AMapDrivingRouteSearchRequest.class])
    {
        int code = -1;
        DriveRouteData data;
        if (response != nil && response.route != nil && response.count > 0)
        {
            self.mRoute = response.route;
            
            AMapPath* path = [response.route.paths objectAtIndex:0];
            if (path != nil)
            {
                code = 0;
                
                data.slat = response.route.origin.latitude;
                data.slng = response.route.origin.longitude;
                data.elat = response.route.destination.latitude;
                data.elng = response.route.destination.longitude;
                data.taxiCost = response.route.taxiCost;
                
                data.distance = (int)[path distance];
                data.duration = (int)[path duration];
                
                data.desctription = [[self getFriendlyTime:(int)[path duration]] UTF8String] + string("(") + [[self getFriendlyLength:(int)[path duration]] UTF8String] + ")";
                
                data.v_steps.reserve(path.steps.count);
                
                for (AMapStep * step in [path steps])
                {
                    RouteStep stepdata;
                    
                    stepdata.distance = (int)step.distance;
                    stepdata.duration = (int)step.duration;
                    stepdata.instruct = [step.instruction UTF8String];
                    stepdata.orientation = [step.orientation UTF8String];
                    
                    data.v_steps.push_back(stepdata);
                }
            }
            
            [self presentRouteView];
        }
        
        AmapViewImpl::onDriveRouteSearched(self, code, data);
    }
    else if ([request isKindOfClass:AMapTransitRouteSearchRequest.class])
    {
        int code = -1;
        std::vector<BusRouteData> datas;
        if (response != nil && response.route != nil && response.count > 0)
        {
            self.mRoute = response.route;
            
            code = 0;
            int tag = 0;
            
            for (AMapTransit * path in response.route.transits)
            {
                datas.reserve(response.route.transits.count);
                
                if (path != nil)
                {
                    BusRouteData data;
                    
                    data.slat = response.route.origin.latitude;
                    data.slng = response.route.origin.longitude;
                    data.elat = response.route.destination.latitude;
                    data.elng = response.route.destination.longitude;
                    
                    data.distance = (int)[path distance];
                    data.duration = (int)[path duration];
                    data.cost = [path cost];
                    
                    data.walkDistance = [path walkingDistance];
                    data.busDistance = 0;
                    
                    data.pathTitle = [[self getBusPathTitle:path] UTF8String];
                    data.pathDes = [[NSString stringWithFormat:@"%ds | %dm | 步行%dm", (int)[path duration], (int)[path distance], (int)[path walkingDistance]] UTF8String];
                    
                    data.tag = tag;
                    tag++;
                    
                    datas.push_back(data);
                }
            }
        }
        
        AmapViewImpl::onBusRouteSearched(self, code, datas);
    }
    else if ([request isKindOfClass:AMapWalkingRouteSearchRequest.class])
    {
        int code = -1;
        WalkRouteData data;
        if (response != nil && response.route != nil && response.count > 0)
        {
            self.mRoute = response.route;
            
            AMapPath* path = [response.route.paths objectAtIndex:0];
            if (path != nil)
            {
                code = 0;
                
                data.slat = response.route.origin.latitude;
                data.slng = response.route.origin.longitude;
                data.elat = response.route.destination.latitude;
                data.elng = response.route.destination.longitude;
                
                data.distance = (int)[path distance];
                data.duration = (int)[path duration];
                
                data.description = [[self getFriendlyTime:(int)[path duration]] UTF8String] + string("(") + [[self getFriendlyLength:(int)[path duration]] UTF8String] + ")";
                
                data.v_steps.reserve(path.steps.count);
                
                for (AMapStep * step in [path steps])
                {
                    RouteStep stepdata;
                    
                    stepdata.distance = (int)step.distance;
                    stepdata.duration = (int)step.duration;
                    stepdata.instruct = [step.instruction UTF8String];
                    stepdata.orientation = [step.orientation UTF8String];
                    
                    data.v_steps.push_back(stepdata);
                }
                
            }
            [self presentRouteView];
        }
        
        AmapViewImpl::onWalkRouteSearched(self, code, data);
    }
}

@end


static std::map<UIAmapViewWrapper*, AmapViewImpl*> s_AMapViewImpls;
AmapViewImpl::AmapViewImpl(AmapView *mapView) : m_pAmapView(mapView), m_pAmapWrapper([UIAmapViewWrapper amapWrapper])
{
    [AmapViewWrapper retain];
    s_AMapViewImpls[AmapViewWrapper] = this;
}

AmapViewImpl::~AmapViewImpl()
{
    clearMarkers();
    
    [AmapViewWrapper release];
    s_AMapViewImpls.erase(AmapViewWrapper);
    
    m_pAmapWrapper = NULL;
}

void AmapViewImpl::setMapCenter(double lat, double lng)
{
    [AmapViewWrapper setMapCenterLat:lat Lng:lng];
}

void AmapViewImpl::startLocation()
{
    [AmapViewWrapper startLocation];
}

void AmapViewImpl::setMapZoomLevel(double level)
{
    [AmapViewWrapper setMapZoomLevel:level];
}

void AmapViewImpl::update(float dt)
{
    DRect cRect = m_pAmapView->convertRectToWorldSpace(m_pAmapView->getBounds());
    cRect.origin.x = s_dip_to_px(cRect.origin.x);
    cRect.origin.y = s_dip_to_px(cRect.origin.y);
    cRect.size.width = s_dip_to_px(cRect.size.width);
    cRect.size.height = s_dip_to_px(cRect.size.height);
    
    CGFloat scale = [[UIScreen mainScreen] scale];
    CGFloat x = cRect.origin.x/scale;
    CGFloat y = cRect.origin.y/scale;
    CGFloat width = cRect.size.width/scale;
    CGFloat height = cRect.size.height/scale;
    
    [AmapViewWrapper setFrameWith_X:x Y:y Width:width Height:height];
}

void AmapViewImpl::addMarker(AmapMarker* marker)
{
    marker->retain();
    
    [AmapViewWrapper addMarkerTag: [NSString stringWithUTF8String:crossapp_format_string("%p", marker).c_str()] Image:[NSString stringWithUTF8String:marker->getImg().c_str()] Draggable:marker->getDraggable() Title:[NSString stringWithUTF8String:marker->getTitle().c_str()] Content:[NSString stringWithUTF8String:marker->getContent().c_str()] Lat:marker->getLat() Lng:marker->getLng()];
    
    s_AmapMarkers[crossapp_format_string("%p", marker)] = marker;
}

void AmapViewImpl::deleteMarker(AmapMarker* marker)
{
    std::map<string, AmapMarker*>::iterator it = s_AmapMarkers.find(crossapp_format_string("%p", marker));
    if (it != s_AmapMarkers.end())
    {
        [AmapViewWrapper deleteMarkerTag:[NSString stringWithUTF8String:crossapp_format_string("%p", marker).c_str()]];
        s_AmapMarkers.erase(it);
        CC_SAFE_RELEASE_NULL(marker);
    }
}

std::map<string, AmapMarker*>& AmapViewImpl::getAllMarkers()
{
    return s_AmapMarkers;
}

void AmapViewImpl::clearMarkers()
{
    for (std::map<string, AmapMarker*>::iterator it = s_AmapMarkers.begin(); it != s_AmapMarkers.end(); ++it)
    {
        CC_SAFE_RELEASE_NULL(it->second);
    }
    
    s_AmapMarkers.clear();
    
    [AmapViewWrapper clearMarkers];
}

void AmapViewImpl::setVisible(bool visible)
{
    [AmapViewWrapper setVisible:visible];
}

void AmapViewImpl::setAmapRouteViewType(double slat, double slng, double elat, double elng, AmapRouteViewType type)
{
    [AmapViewWrapper setAmapRouteViewTypeSLat:slat SLng:slng ELat:elat ELng:elng Type:type];
}

void AmapViewImpl::searchRoute()
{
    [AmapViewWrapper searchRoute];
}

void AmapViewImpl::showBusRouteView(const int bustag)
{
    [AmapViewWrapper showBusRouteView:bustag];
}

void AmapViewImpl::setBusRouteCity(const string& city, const string& cityd)
{
    [AmapViewWrapper setBusRouteCity:[NSString stringWithUTF8String:city.c_str()] CityD:[NSString stringWithUTF8String:cityd.c_str()]];
}

void AmapViewImpl::getBusRouteStep(int bustag)
{
    [AmapViewWrapper getBusRouteStep:bustag];
}

void AmapViewImpl::onAmapClicked(void* amapwrapper, double lat, double lng)
{
    std::map<UIAmapViewWrapper*, AmapViewImpl*>::iterator it = s_AMapViewImpls.find((UIAmapViewWrapper*)amapwrapper);
    if (it != s_AMapViewImpls.end())
    {
        AmapView* ampView = it->second->m_pAmapView;
        if (ampView && ampView->getAmapViewDelegate())
        {
            ampView->getAmapViewDelegate()->onAmapClicked(lat, lng);
        }
    }
}

void AmapViewImpl::onAmapLocationEnd(void* amapwrapper, int code, double lat, double lng, const string& formatAddr, const string& province, const string& city, const string& district, const string& street, const string& number, const string& poi, const string& adcode)
{
    std::map<UIAmapViewWrapper*, AmapViewImpl*>::iterator it = s_AMapViewImpls.find((UIAmapViewWrapper*)amapwrapper);
    if (it != s_AMapViewImpls.end())
    {
        AmapView* ampView = it->second->m_pAmapView;
        if (ampView && ampView->getAmapViewDelegate())
        {
            ampView->getAmapViewDelegate()->onAmapLocationEnd(code, lat, lng, formatAddr, province, city, district, street, number, poi, adcode);
        }
    }
}

void AmapViewImpl::onAmapMarkerDragStart(void* amapwrapper, const string& markertag, double lat, double lng)
{
    std::map<UIAmapViewWrapper*, AmapViewImpl*>::iterator it = s_AMapViewImpls.find((UIAmapViewWrapper*)amapwrapper);
    if (it != s_AMapViewImpls.end())
    {
        std::map<string, AmapMarker*>::iterator mIt = it->second->getAllMarkers().find(markertag);
        if (mIt != it->second->getAllMarkers().end())
        {
            AmapView* ampView = it->second->m_pAmapView;
            if (ampView && ampView->getAmapViewDelegate())
            {
                ampView->getAmapViewDelegate()->onAmapMarkerDragStart(mIt->second, lat, lng);
            }
        }
    }
}

void AmapViewImpl::onAmapMarkerDrag(void* amapwrapper, const string& markertag, double lat, double lng)
{
    std::map<UIAmapViewWrapper*, AmapViewImpl*>::iterator it = s_AMapViewImpls.find((UIAmapViewWrapper*)amapwrapper);
    if (it != s_AMapViewImpls.end())
    {
        std::map<string, AmapMarker*>::iterator mIt = it->second->getAllMarkers().find(markertag);
        if (mIt != it->second->getAllMarkers().end())
        {
            AmapView* ampView = it->second->m_pAmapView;
            if (ampView && ampView->getAmapViewDelegate())
            {
                ampView->getAmapViewDelegate()->onAmapMarkerDrag(mIt->second, lat, lng);
            }
        }
    }
}

void AmapViewImpl::onAmapMarkerDragEnd(void* amapwrapper, const string& markertag, double lat, double lng)
{
    std::map<UIAmapViewWrapper*, AmapViewImpl*>::iterator it = s_AMapViewImpls.find((UIAmapViewWrapper*)amapwrapper);
    if (it != s_AMapViewImpls.end())
    {
        std::map<string, AmapMarker*>::iterator mIt = it->second->getAllMarkers().find(markertag);
        if (mIt != it->second->getAllMarkers().end())
        {
            AmapView* ampView = it->second->m_pAmapView;
            if (ampView && ampView->getAmapViewDelegate())
            {
                ampView->getAmapViewDelegate()->onAmapMarkerDragEnd(mIt->second, lat, lng);
            }
        }
    }
}

void AmapViewImpl::onAmapMarkerClick(void* amapwrapper, const string& markertag)
{
    std::map<UIAmapViewWrapper*, AmapViewImpl*>::iterator it = s_AMapViewImpls.find((UIAmapViewWrapper*)amapwrapper);
    if (it != s_AMapViewImpls.end())
    {
        std::map<string, AmapMarker*>::iterator mIt = it->second->getAllMarkers().find(markertag);
        if (mIt != it->second->getAllMarkers().end())
        {
            AmapView* ampView = it->second->m_pAmapView;
            if (ampView && ampView->getAmapViewDelegate())
            {
                ampView->getAmapViewDelegate()->onAmapMarkerClick(mIt->second);
            }
        }
    }
}

void AmapViewImpl::onAmapMarkerInfoWindowClick(void* amapwrapper, const string& markertag)
{
    std::map<UIAmapViewWrapper*, AmapViewImpl*>::iterator it = s_AMapViewImpls.find((UIAmapViewWrapper*)amapwrapper);
    if (it != s_AMapViewImpls.end())
    {
        std::map<string, AmapMarker*>::iterator mIt = it->second->getAllMarkers().find(markertag);
        if (mIt != it->second->getAllMarkers().end())
        {
            AmapView* ampView = it->second->m_pAmapView;
            if (ampView && ampView->getAmapViewDelegate())
            {
                ampView->getAmapViewDelegate()->onAmapMarkerInfoWindowClick(mIt->second);
            }
        }
    }
}

void AmapViewImpl::onDriveRouteSearched(void* amapwrapper, int code, DriveRouteData data)
{
    std::map<UIAmapViewWrapper*, AmapViewImpl*>::iterator it = s_AMapViewImpls.find((UIAmapViewWrapper*)amapwrapper);
    if (it != s_AMapViewImpls.end())
    {
        AmapView* ampView = it->second->m_pAmapView;
        if (ampView && ampView->getAmapViewDelegate())
        {
            ampView->getAmapViewDelegate()->onDriveRouteSearched(code, data);
        }
    }
}

void AmapViewImpl::onWalkRouteSearched(void* amapwrapper, int code, WalkRouteData data)
{
    std::map<UIAmapViewWrapper*, AmapViewImpl*>::iterator it = s_AMapViewImpls.find((UIAmapViewWrapper*)amapwrapper);
    if (it != s_AMapViewImpls.end())
    {
        AmapView* ampView = it->second->m_pAmapView;
        if (ampView && ampView->getAmapViewDelegate())
        {
            ampView->getAmapViewDelegate()->onWalkRouteSearched(code, data);
        }
    }
}

void AmapViewImpl::onBusRouteSearched(void* amapwrapper, int code, std::vector<BusRouteData> data)
{
    std::map<UIAmapViewWrapper*, AmapViewImpl*>::iterator it = s_AMapViewImpls.find((UIAmapViewWrapper*)amapwrapper);
    if (it != s_AMapViewImpls.end())
    {
        AmapView* ampView = it->second->m_pAmapView;
        if (ampView && ampView->getAmapViewDelegate())
        {
            ampView->getAmapViewDelegate()->onBusRouteSearched(code, data);
        }
    }
}

void AmapViewImpl::onBusRouteSteps(void* amapwrapper, int code, const int bustag, std::vector<BusRouteStep> data)
{
    std::map<UIAmapViewWrapper*, AmapViewImpl*>::iterator it = s_AMapViewImpls.find((UIAmapViewWrapper*)amapwrapper);
    if (it != s_AMapViewImpls.end())
    {
        AmapView* ampView = it->second->m_pAmapView;
        if (ampView && ampView->getAmapViewDelegate())
        {
            ampView->getAmapViewDelegate()->onBusRouteSteps(code, bustag, data);
        }
    }
}

